//
//  Store_ViewController.m
//  penzer
//
//  Created by caiyc on 2018/10/28.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "Store_ViewController.h"
#import "StoreListCell.h"
@interface Store_ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSMutableArray *dataSorce;
@end

@implementation Store_ViewController
-(NSMutableArray *)dataSorce{
    if(!_dataSorce){
        _dataSorce = [NSMutableArray array];
    }
    return _dataSorce;
}

- (void)viewDidLoad {
    [super viewDidLoad];
      [self setNavigation:1 andTitle:@"选择消费门店" andNaviColor:[UIColor clearColor] andTitleColor:nil];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self loadData];
    // Do any additional setup after loading the view from its nib.
}
-(void)loadData{
//http://dev.sharepanzer.com/api/bzapi.php?i=10&c=entry&ctrl=live&ac=store&op=goods&m=bz_activities&token=194d7d75d1b6ac4ed794a53732af625e&ta=detail
    NSDictionary *paramter = @{@"op":@"goods",@"ctrl":@"live",@"ac":@"store",@"ta":@"detail",@"id":self.ids};
    [self weqPostHandle:paramter success:^(id response) {
        if(response){
            if(response){
                NSArray *lists = response[@"data"][@"store_list"];
                if(lists.count>0){
                    [self.dataSorce addObjectsFromArray:lists];
                    [self.tableView reloadData];
                }
            }
        }
    } failure:^(NSError *error) {
        
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSorce.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellId = @"cell";
    StoreListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId];
    if(!cell){
        cell = [[[NSBundle mainBundle]loadNibNamed:@"StoreListCell" owner:self options:nil]lastObject];
    }
     NSDictionary *dic = self.dataSorce[indexPath.row];
    cell.pickStores=^(){
        self.selctStore(dic);
        [self.navigationController popViewControllerAnimated:1];
    };
    [cell bindData:self.dataSorce[indexPath.row]];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
//    self.selctStore(dic);
//    [self.navigationController popViewControllerAnimated:1];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
